# Avatar model
from datetime import datetime
from sqlalchemy import (
    Column, BigInteger, Integer, String, Text, DateTime, Boolean, Enum, JSON
)
from sqlalchemy.orm import relationship
from ..database import Base


class Avatar(Base):
    __tablename__ = "avatars"
    
    id = Column(BigInteger, primary_key=True, index=True, comment="数字人ID")
    name = Column(String(100), nullable=False, comment="数字人名称")
    description = Column(Text, nullable=True, comment="描述")
    model_url = Column(String(255), nullable=False, comment="3D模型文件URL")
    thumbnail = Column(String(255), nullable=True, comment="缩略图URL")
    gender = Column(
        Enum("male", "female", name="gender_enum"),
        nullable=False,
        comment="性别"
    )
    age_range = Column(String(20), nullable=True, comment="年龄范围")
    personality = Column(JSON, nullable=True, comment="性格特征")
    voice_config = Column(JSON, nullable=True, comment="语音配置")
    animation_config = Column(JSON, nullable=True, comment="动画配置")
    usage_count = Column(Integer, default=0, nullable=True, comment="使用次数")
    created_at = Column(
        DateTime, default=datetime.utcnow, nullable=False, comment="创建时间"
    )
    updated_at = Column(
        DateTime, 
        default=datetime.utcnow, 
        onupdate=datetime.utcnow, 
        nullable=False, 
        comment="更新时间"
    )
    is_active = Column(Boolean, default=True, nullable=True, comment="是否可用")
    
    # 关系
    chat_sessions = relationship("ChatSession", back_populates="avatar") 